package com.weixin.engine.daily.thread;

/**
 * @author wangchunhui
 * @date 2022/11/8 10:12
 */
public class ThreadExceptionDemo {

    public static void main(String[] args) {
        Thread thread1 = getThread1();

        Thread thread2 = new Thread(() -> thread1.start(), "线程2");

        thread2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread t, Throwable e) {
                System.out.println(t.getName() + "-----------" + e.getMessage());
            }
        });
        thread2.start();
    }

    private static Thread getThread1() {
        return new Thread(() -> {
            throw new RuntimeException("123456");
        }, "线程1");
    }
}
